home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Software Vault: The Games Collection 1
/
software vault.zip
/
software vault
/
CDR10
/
MAPEDIT.ZIP
/
PAINT.C
< prev
next >
Wrap
C/C++ Source or Header
|
1993-05-13
|
12KB
|
466 lines
#include "paint.h"
main(int argc, char **argv)
{
int x=0;
int y=0;
char cbuf[128],copybuf[64];
int oldmouse;
unsigned int loop;
tbar=160;
cvis=0; lcol=1;
mcol=2; rcol=100;
cchar=0; mapx=0;
mapy=0; chy=6;
mouseon=0;
current_mode=NORMAL_MODE;
if(argc<3)
{
printf("\nUsage :");
printf("\n%s characterset.pcx mapname",argv[0]);
exit(0);
}
if(!mousecheck())
{
printf("\nThis Program requires a mouse and a mouse driver to run.");
exit(0);
}
if(! (bufptr = (char far *)malloc(64001)))
{
printf("\nNot enough free memory. (bufptr)");
exit(0);
}
if(! (mapptr = (int far *)malloc(64001)))
{
printf("\nNot enough free memory. (mapptr)");
exit(0);
}
if(! (ca = (struct character_attribute_struct far *)malloc(sizeof(struct character_attribute_struct)*1000 )))
{
printf("\nNot enough free memory. (ca - character attribute)");
exit(0);
}
load_db();
load_map(argv[2]);
load_charset();
load_attributes();
memset(screen,0xff,2000);
printf("\nLoading Paint program.");
load_pcx(argv[1],bufptr);
strcpy(mapname,argv[2]);
strcpy(charsetname,argv[1]);
makepal();
vmode(0x13);
set_palette();
show_sprite(0,tbar,"mainmenubar");
show_map(mapx,mapy,1,tbar/8);
show_chset(tbar+8,chy);
mousecursor(1);
mouseon=1;
// ask_chset(); not completed yet!!!!
for(;;)
{
mousex=mousecol();
mousey=mouserow();
if(mousey<8)
{
setrow(8);
mousey=8;
}
update_screen();
update_sbar();
if(mouseb=mousebuttons())
{
if(mousey<tbar)
maphit();
else if(mousey<tbar+8)
barhit();
else
chsethit();
}
else
{
if(current_mode==DRAW_MODE)
current_mode=NORMAL_MODE;
}
}
}
update_sbar()
{
char temps[80];
int loop;
if(mousey<tbar)
sprintf(temps,"X:%3d Y:%3d Value: %4d ",mapx+mousex/8,mapy+mousey/8-1,mapptr[mapx+mousex/8+(mapy+mousey/8)*320]);
else if(mousey>tbar+8)
sprintf(temps,"X:%3d Y:%3d Value: %4d ",mousex/8,chy+(mousey-tbar)/8-1,mousex/8+((mousey-tbar)/8+chy-1)*40);
else
strcpy(temps," ");
putsline(0,temps);
if(ca[cchar].block)
{
sprintf(temps,"%s %s %s %s",(ca[cchar].block&TOP_BLOCK ? "T":" "),(ca[cchar].block&BOTTOM_BLOCK ? "B":" "),(ca[cchar].block&LEFT_BLOCK ? "L":" "),(ca[cchar].block&RIGHT_BLOCK ? "R":" "));
putsline(26,temps);
}
else
putsline(26," ");
sprintf(temps,"%3d:",cchar);
putsline(34,temps);
pch(38,0,cchar);
}
maphit()
{
static int fromx,fromy;
int loop;
if(mouseb==2)
{
cchar=mapptr[mapx+mousex/8+(mapy+mousey/8)*320];
current_mode=NORMAL_MODE;
show_sprite(0,tbar,"mainmenubar");
}
else
{
memset(screen,0xff,2000);
switch(current_mode)
{
case DRAW_MODE:
mapline(mapx,mapy,fromx/8,fromy/8,mousex/8,mousey/8,cchar);
case NORMAL_MODE:
mapptr[mapx+mousex/8+(mapy+mousey/8)*320]=cchar;
fromx=mousex;
fromy=mousey;
current_mode=DRAW_MODE;
break;
case EDIT_MODE:
edit_pix(mapptr[mapx+mousex/8+(mapy+mousey/8)*320]%40,mapptr[mapx+mousex/8+(mapy+mousey/8)*320]/40);
for(loop=0;loop<1000;loop++)
screen[loop]=0xffff;
current_mode=NORMAL_MODE;
show_sprite(0,tbar,"mainmenubar");
show_map(mapx,mapy,1,tbar/8);
show_chset(tbar+8,chy);
show_sprite(0,tbar,"mainmenubar");
break;
case COPY_MODE:
cchar=mapptr[mapx+mousex/8+(mapy+mousey/8)*320];
current_mode=NORMAL_MODE;
show_sprite(0,tbar,"mainmenubar");
break;
}
}
}
barhit()
{
int oldmouse;
if(mousex>48 && mousex<60 )
{
show_sprite(50,tbar,"smalldown");
do{
if(chy<(tbar/8))
{
chy++;
vwait();
show_chset(tbar+8,chy);
}
}
while(mousebuttons()==2)
;
while(mousebuttons()==1)
;
show_sprite(0,tbar,"mainmenubar");
}
if(mousex>154 && mousex<174)
{
show_sprite(155,tbar,"save");
ask_save();
}
if(mousex>134 && mousex<154)
{
current_mode=COPY_MODE;
show_sprite(135,tbar,"copy");
while(mousebuttons())
;
show_sprite(0,tbar,"pickcopyfrom");
}
if(mousex>0 && mousex<0)
{
show_sprite(135,tbar,"f");
while(mousebuttons())
;
show_sprite(0,tbar,"mainmenubar");
}
if(mousex>59 && mousex<69)
{
show_sprite(60,tbar,"topin");
process_block(TOP_BLOCK);
while(mousebuttons())
;
show_sprite(0,tbar,"mainmenubar");
}
if(mousex>69 && mousex<79)
{
show_sprite(70,tbar,"bottomin");
process_block(BOTTOM_BLOCK);
while(mousebuttons())
;
show_sprite(0,tbar,"mainmenubar");
}
if(mousex>79 && mousex<89)
{
show_sprite(80,tbar,"leftin");
process_block(LEFT_BLOCK);
while(mousebuttons())
;
show_sprite(0,tbar,"mainmenubar");
}
if(mousex>89 && mousex<99)
{
show_sprite(90,tbar,"rightin");
process_block(RIGHT_BLOCK);
while(mousebuttons())
;
show_sprite(0,tbar,"mainmenubar");
}
if(mousex>99 && mousex<116)
{
show_sprite(100,tbar,"allin");
process_block(ALL_BLOCK);
while(mousebuttons())
;
show_sprite(0,tbar,"mainmenubar");
}
if(mousex<9 )
{
show_sprite(0,tbar,"smallup");
do
{
if(chy>0)
{
chy--;
show_chset(tbar+8,chy);
}
}
while(mousebuttons()==2);
while(mousebuttons()==1)
;
show_sprite(0,tbar,"mainmenubar");
}
if(mousex>175 && mousex<194)
{
show_sprite(175,tbar,"exit");
while(mousebuttons())
;
show_sprite(0,tbar,"mainmenubar");
ask_exit();
}
if(mousex>119 && mousex< 131)
{
mousecursor(0);
mouseon=0;
oldmouse=mousey;
while(mousebuttons()==1)
{
mousey=mouserow();
tbar=mousey & 0xFFF8;
if(tbar<8)
tbar=8;
memset(screen,0xff,2000);
vwait();
show_sprite(0,tbar,"movemainmenu");
if(mapy>100-tbar/8)
{
mapy=100-tbar/8;
show_map(mapx,mapy,1,tbar/8);
}
else if(oldmouse<tbar/8)
show_map(mapx,mapy,oldmouse,tbar/8);
if(chy>(tbar/8))
chy=tbar/8;
show_chset(tbar+8,chy);
oldmouse=tbar/8;
}
show_sprite(0,tbar,"mainmenubar");
}
if(mousex>294 && mousex<306)
{
show_sprite(295,tbar,"bigdown");
do{
if(mapy<100-tbar/8)
{
mapy++;
show_map(mapx,mapy,1,tbar/8);
}
}
while(mousebuttons()==2);
while(mousebuttons()==1);
show_sprite(0,tbar,"mainmenubar");
}
if(mousex>282 && mousex<293 )
{
show_sprite(282,tbar,"bigup");
do{
if(mapy>0)
{
mapy--;
show_map(mapx,mapy,1,tbar/8);
}
}
while(mousebuttons()==2);
while(mousebuttons()==1)
;
show_sprite(0,tbar,"mainmenubar");
}
if(mousex>308 && mousex<320)
{
show_sprite(308,tbar,"bigright");
do{
if(mapx<320-40)
{
mapx++;
show_map(mapx,mapy,1,tbar/8);
}
}
while(mousebuttons()==2);
while(mousebuttons()==1)
;
show_sprite(0,tbar,"mainmenubar");
}
if(mousex>195 && mousex<216)
{
show_sprite(196,tbar,"edit");
while(mousebuttons())
;
show_sprite(0,tbar,"pickedit");
current_mode=EDIT_MODE;
}
if(mousex>269 && mousex<280)
{
show_sprite(269,tbar,"bigleft");
do{
if(mapx>0)
{
mapx--;
show_map(mapx,mapy,1,tbar/8);
}
}
while(mousebuttons()==2);
while(mousebuttons()==1);
show_sprite(0,tbar,"mainmenubar");
}
}
chsethit()
{
char temps[128];
int loop;
switch(current_mode)
{
case NORMAL_MODE:
cchar=mousex/8+((mousey-tbar)/8+chy-1)*40;
break;
case EDIT_MODE:
edit_pix(mousex/8,(mousey-tbar)/8+chy-1);
for(loop=0;loop<1000;loop++)
screen[loop]=0xffff;
show_sprite(0,tbar,"mainmenubar");
show_map(mapx,mapy,1,tbar/8);
show_chset(tbar+8,chy);
current_mode=NORMAL_MODE;
break;
case DEST_MODE:
btc(cchar%40,cchar/40,temps);
ctb(mousex/8,(mousey-tbar)/8+chy-1,temps);
while(mousebuttons());
show_sprite(0,tbar,"mainmenubar");
current_mode=NORMAL_MODE;
break;
case COPY_MODE:
cchar=mousex/8+((mousey-tbar)/8+chy-1)*40;
show_sprite(0,tbar,"pickpasteto");
while(mousebuttons());
current_mode=DEST_MODE;
break;
}
}
update_screen()
{
if(mousey<tbar)
{
if(mouseon)
{
mousecursor(0);
mouseon=0;
}
vwait();
cross(mousex,mousey,8,tbar);
vwait();
block(mousex/8,mousey/8,0);
vwait();
block(mousex/8,mousey/8,1);
vwait();
cross(mousex,mousey,8,tbar);
pch(mousex/8,mousey/8,mapptr[mapx+mousex/8+(mapy+mousey/8)*320]);
}
else if(mousey<tbar+8 )
{
if(!mouseon)
{
mousecursor(1);
mouseon=1;
waitup();
}
}
else
{
if(mouseon)
{
mousecursor(0);
mouseon=0;
}
vwait();
block(mousex/8,mousey/8,0);
vwait();
block(mousex/8,mousey/8,1);
vwait();
pch(mousex/8,mousey/8,mousex/8+((mousey-tbar)/8+chy-1)*40);
}
}
process_block(int blocks)
{
switch(blocks)
{
case TOP_BLOCK:
ca[cchar].block ^=TOP_BLOCK;
break;
case BOTTOM_BLOCK:
ca[cchar].block ^=BOTTOM_BLOCK;
break;
case LEFT_BLOCK:
ca[cchar].block^=LEFT_BLOCK;
break;
case RIGHT_BLOCK:
ca[cchar].block ^=RIGHT_BLOCK;
break;
case ALL_BLOCK:
if(ca[cchar].block==ALL_BLOCK)
ca[cchar].block=0;
else
ca[cchar].block=ALL_BLOCK;
}
}